package cms.service.upload;

import cms.bean.setting.EditorTag;
import cms.bean.user.AccessUser;
import cms.bean.user.ResourceEnum;
import cms.common.data.ApiResultCode;
import cms.common.exception.ServiceException;
import org.springframework.stereotype.Service;

@Service("imageBeService")
public class ImageBeService extends BaseFileService implements FileService {

    @Override
    protected UpFileType uploadHander(String model, AccessUser accessUser) {
        //是否有当前功能操作权限
        boolean isPermission = userRoleManage.isPermission(ResourceEnum._2002000, null, accessUser);
        if (isPermission) {
            EditorTag editorTag = getEditorTag(model);
            if (editorTag.isImage()) { //允许上传图片
                return new UpFileType(editorTag.getImageFormat(), editorTag.getImageSize());
            }
        }
        throw new ServiceException(ApiResultCode.NO_PERMISSION.setMessage("上传图片文件权限不足"));
    }
}
